package com.aracky.assess.service.impl;

import com.aracky.assess.model.entity.HrKpiUserPerformanceHeader;
import com.aracky.assess.model.vo.HrKpiUserPerformanceHeaderVO;
import com.aracky.assess.outside.StartFlowable;
import com.aracky.assess.service.HrKpiUserPerformanceHeaderService;
import com.aracky.assess.service.PushFlowService;
import com.aracky.assess.util.FlowableUtil;
import com.aracky.common.annotation.DataDeal;
import com.aracky.common.util.ConvertUtil;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @Author zengzhiping
 * @BelongsPackage com.aracky.assess.service.impl
 * @CreateTime 2022-08-26
 * @Description
 */
@Service
public class PushFlowServiceImpl implements PushFlowService {

    @Autowired
    private FlowableUtil flowableUtil;

    @Autowired
    private HrKpiUserPerformanceHeaderService kpiUserPerformanceHeaderService;

    @Override
    public void batchAssessFlowStart(List<HrKpiUserPerformanceHeaderVO> headerVOList, String processKey) {

        //构造数据
        List<StartFlowable> flowableList = new ArrayList<>();
        for (HrKpiUserPerformanceHeaderVO head : headerVOList) {
            StartFlowable startFlowable = new StartFlowable();
            startFlowable.setProcessDefinitionKey(processKey);
            startFlowable.setBusinessKey(String.valueOf(head.getId()));
            //存放所需参数
            HashMap<String, Object> hashMap = Maps.newHashMap();
            hashMap.put("employeeId", String.valueOf(head.getUserId()));
            hashMap.put("desc", head.getPerformancePeriod() + head.getPerformanceTypeName() + "填写");
            startFlowable.setMap(hashMap);
            flowableList.add(startFlowable);
        }
        flowableUtil.batchStartProcess(flowableList);
    }


    @DataDeal(dict = true, user = true)
    public List<HrKpiUserPerformanceHeaderVO> buildHeaderListVO(List<HrKpiUserPerformanceHeader> hrKpiUserPerformanceHeaderList) {
        HrKpiUserPerformanceHeader byId = kpiUserPerformanceHeaderService.getById(3909);
        hrKpiUserPerformanceHeaderList.add(byId);
        return ConvertUtil.sourceToTargets(hrKpiUserPerformanceHeaderList, HrKpiUserPerformanceHeaderVO.class);
    }


}
